package com.zengjin.test.controller;

import com.zengjin.test.common.PageResponse;
import com.zengjin.test.common.R;
import com.zengjin.test.model.dto.UserDto;
import com.zengjin.test.model.vo.UserVo;
import com.zengjin.test.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 19324
 */
@Tag(name = "用户相关接口")
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Resource
    private UserService userService;

    //1.新增
    @Operation(summary = "新增User")
    @PostMapping("/create")
    public R<Boolean> create(@RequestBody UserDto userDto){
        userService.create(userDto);
        return R.success("新增成功");
    }

    //2.查询ByUserId
    @Operation(summary = "查询ByUserId")
    @PostMapping("/queryByUserId")
    public R<UserVo> queryByUserId(@RequestBody UserDto userDto){
        UserVo userVo=userService.queryByUserId(userDto);
        return R.success(userVo,"查询成功");
    }

    //3.查询By其他字段
    @Operation(summary = "查询By其他字段")
    @PostMapping("/queryByOther")
    public R<UserVo> queryByOther(@RequestBody UserDto userDto){
        UserVo userVo=userService.queryByOther(userDto);
        return R.success(userVo,"查询成功");
    }

    //4.查询所有
    @Operation(summary = "查询所有User")
    @PostMapping("/queryAll")
    public R<List<UserVo>> queryAll(){
        List<UserVo> userVoList=userService.queryAll();
        return R.success(userVoList,"查询成功");
    }

    //5.删除ByUserId
    @Operation(summary = "删除ByUserId")
    @PostMapping("/deleteByUserId")
    public R<Boolean> deleteByUserId(@RequestBody UserDto userDto){
        userService.deleteByUserId(userDto);
        return R.success("删除成功");
    }

    //6.修改ByUserId
    @Operation(summary = "修改ByUserId")
    @PostMapping("/updateByUserId")
    public R<Boolean> updateByUserId(@RequestBody UserDto userDto){
        userService.updateByUserId(userDto);
        return R.success("修改成功");
    }

    //7.分页查询User
    @Operation(summary = "分页查询User")
    @PostMapping("/queryUserByPage")
    public R<PageResponse<UserVo>> queryByPage(@RequestBody UserDto userDto){
        PageResponse<UserVo> pageResponse=userService.queryUserByPage(userDto);
        return R.success(pageResponse,"查询成功");
    }
}
